<template>
	<view class="main">
			<u-navbar :is-back="true" title="商品管理" :background="background" back-icon-color="#000000" title-color="#000" title-bold="true">
				<view class="rights" slot="right" @click="router('../shop_manage/shop_manage')">
					分类管理
				</view>
			</u-navbar>
			
			<view class="serch">
				<u-search :clearabled="true" shape="square" bg-color="#fff" placeholder="输入搜索关键字":show-action="false" v-model="keywords" @search="selectshoplist"></u-search>
			</view>
			<view class="content" v-for="(item,index) in shoplist" :key="index">
				<view class="shop">
					<image :src="item.image" mode=""></image>
					<view class="shop_r">
						<view class="shop_tit">
							{{item.name}}
						</view>
						<view class="status">
							{{item.on_sale==1?'在售中':'已下架'}}
						</view>
						<view class="money">
							¥{{item.minPrice}}-{{item.maxPrice}}
						</view>
					</view>
				</view>
				<view class="button">
					<view :class="item.on_sale==0?'under':'on'"  @click="putdown(item.id,1)">
						上架
					</view>
					<view  :class="item.on_sale==1?'under':'on'" @click="putdown(item.id,0)">
						下架
					</view>
					<view class="change" @click="router('../shop_change/shop_change',item)">
						编辑
					</view>
				</view>
			</view>
			<view class="confirm"  @click="router('../add_shop/add_shop')">
				添加商品
			</view>
	</view>
</template>
<script>


	export default {
		data() {
			return {
				background: {
					backgroundColor:'#fff'
				},
				shoplist:[],//商品列表
				keywords:''
			
			}
		},
		onLoad() {
			this.selectshoplist()//查询商品列表
		},
		mounted() {
		
		},
		onShow() {
		},
		methods: {
			//跳转注释
			router(path,details){
				uni.navigateTo({
					url:path+ '?details=' + encodeURIComponent(JSON.stringify(details))
				})
			},
			//查询商品列表
			selectshoplist(){
				global.$http.request({
					url:'/shopapi/goods/goodList',
					data:{
						token:uni.getStorageSync('token'),
						keywords:this.keywords
					}
				}).then(res=>{
					if(res.data.code==200){
						console.log(res.data.data);
						this.shoplist=res.data.data
					}
				})
			},
			putdown(id,status){
				global.$http.request({
					url:'/shopapi/goods/goodup',
					data:{
						token:uni.getStorageSync('token'),
						goodid:id,
						sale:status
					}
				}).then(res=>{
					if(res.data.code==200){
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:700
						})
						this.selectshoplist()
					}
				})
			},

			
		}
	}
</script>
<style lang="scss">
	page {
		font-family: PingFang SC;
		width: 750rpx;
		padding-bottom: 250rpx;
		
		background-color: #f7f7f7;
		.main {
			width: 750rpx;
			margin: 0 auto;
			.rights{
				font-size: 30rpx;
				font-weight: 400;
				color: #FE4E00;
				padding-right: 20rpx;
			}
			.serch{
				margin: 20rpx;
			}
			.content{
				background-color: #fff;
				padding: 25rpx 25rpx 0 25rpx;
				.shop{
					padding-bottom: 40rpx;
					display: flex;
					image{
						width: 180rpx;
						height: 180rpx;
					}
					.shop_r{
								padding-left: 26rpx;
						.shop_tit{
							font-size: 28rpx;
							font-weight: 400;
							color: #000000;
						}
					}
					.status{
						padding: 32rpx 0 17rpx 0;
						font-size: 24rpx;
						font-weight: 400;
						color: #FF0707;
					}
					.money{
						font-size: 24rpx;
						font-weight: 400;
						color: #010101;
					}
				}
				.button{
					padding: 15rpx;
					border-top: 2rpx solid #F7F7F7;
					border-bottom: 2rpx solid #F7F7F7;
					display: flex;
					justify-content: space-around;
					text-align: center;
					font-size: 24rpx;
					font-weight: 400;
					.on{
					width: 120rpx;
					height: 48rpx;
					line-height: 45rpx;
					background: #FFFFFF;
					border: 1px solid #B3B3B3;
					border-radius: 24rpx;
					color: #B3B3B3;
					}
					.under{
						width: 120rpx;
						height: 48rpx;
						line-height: 48rpx;
						background: #7F7F7F;
						border-radius: 24rpx;
						color: #FFFFFF;
					}
					.change{
						width: 120rpx;
						height: 48rpx;
						line-height: 48rpx;
						background: #0F82FF;
						border-radius: 24rpx;
						font-family: PingFang SC;
						color: #FFFFFF;
					}
				}
			}
			.confirm {
				position: fixed;
				bottom: 0;
				width: 750rpx;
				text-align: center;
				padding: 34rpx 0;
				background: #FE4E00;
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
			}
		}
	}
</style>
